package com.ruoyi.web.controller.survey;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.survey.SurveyInfo;
import com.ruoyi.system.domain.survey.SurveyQuestion;
import com.ruoyi.system.domain.survey.SurveyQuestionVo;
import com.ruoyi.system.service.survey.ISurveyQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问卷问题信息
 *
 * @author ruoyi
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/survey/surveyQuestion")
public class SurveyQuestionController extends BaseController {

    @Autowired
    private ISurveyQuestionService surveyQuestionService;
    /**
     * 查询问卷信息，存储问卷的基本信息，包括ID、标题、描述和时间戳列表
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:list')")
    @PostMapping("/questionById")
    public TableDataInfo questionById(@RequestBody SurveyInfo surveyInfo)
    {
        List<SurveyQuestion> list = surveyQuestionService.selectSurveyQuestionBySurveyId(surveyInfo.getSurveyId());
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     *  更新问卷题库
     *
     * @author sergio
     * @date 2024/11/27
     */
    @PreAuthorize("@ss.hasPermi('survey:surveyInfo:edit')")
    @PostMapping("/updateQuestion")
    public int updateQuestion(@RequestBody SurveyQuestionVo surveyQuestionVo)
    {
        System.out.println(surveyQuestionVo);
        int status = surveyQuestionService.updateQuestionBySurveyId(surveyQuestionVo);
//        List<SurveyQuestion> list = surveyQuestionService.selectSurveyQuestionBySurveyId(surveyInfo.getSurveyId());
//        return getDataTable(list);
        return status;
    }

}
